
#region Imported Namespaces
using System;
using System.Runtime.InteropServices;
#endregion

namespace PHSRAG.Utility
{
	#region Class Tracer
	/// <summary>
	/// The Tracer class is used to send strings to the same debug target as used by the Win32 API OutputDebugString.
	/// This provides us with a simple facility to log whatever we want even when the calling application is not running
	/// in a debugger context. Typically, an application such as the DebugView from SysInternals would be run to capture
	/// the output.
	/// </summary>
	/// <remarks>
	/// It is of significance to note that this class has a single static method declaration but absolutely no logic at
	/// all! All we do is to provide a .NET binding to the Win32 API OutputDebugString using the alias "Trace".
	/// Usage of this would take the following form:
	/// PHSRAG.Utility.Tracer.Trace("whatever you want to say");
	/// </remarks>
	[Guid("5A40E7AB-EB38-4e63-927B-2536FA7B01C0")]
	public class Tracer
	{
		#region InterOp
		/// <summary>
		/// The Trace method is the public interface into the Tracer facility. It is an alias to the OutputDebugStringW API.
		/// </summary>
		/// <param name="s">String to send to the trace listener</param>
		[DllImport("Kernel32.dll", EntryPoint="OutputDebugStringW", CharSet=CharSet.Unicode)]
		public static extern void Trace(string s);
		#endregion

		#region Public Methods
		/// <summary>
		/// This instance method is ONLY provided to allow invocation via COM (in which context, static methods don't get
		/// exported to the type libarary). This method delegates to the static Trace method.
		/// </summary>
		/// <param name="s">String to send to the trace listener</param>
		public static void Log(string s)
		{
			Trace(s);
		}
		#endregion
	}
	#endregion
}

// --- EOF ---
